# coding=utf-8
import csv
import os
import sys
from pathlib import Path


class LimitCsvProcess():
    def __init__(self,Limit_csv_path= os.path.join(Path(__file__).parent.parent,"Assets/Limits.csv")):
    
        self.Limit_csv_path = Limit_csv_path
        self.contentArray = []
        # print("+++++++++++++++++++++++=")
        # print(self.Limit_csv_path)
        self.getCsvContent()

    def getCsvContent(self):
        Limit_csv_path = self.Limit_csv_path
    
        with open(Limit_csv_path,encoding = "utf-8-sig",mode = "r") as f:
            dictReader = csv.DictReader(f)
            
            TestName_Flag = ""
            for row in dictReader:
                perLineDic = {}
       
                perLineDic["TestName"] = row["TestName"]
                perLineDic["ParameterName"] = row["ParameterName"]
                perLineDic["units"] = row["units"]
                perLineDic["upperLimit"] = row["upperLimit"]
                perLineDic["lowerLimit"] = row["lowerLimit"]
                perLineDic["relaxedUpperLimit"] = row["relaxedUpperLimit"]
                perLineDic["relaxedLowerLimit"] = row["relaxedLowerLimit"]
                
                self.contentArray.append(perLineDic)
        
        return self.contentArray

    # 根据TestName从Limit中取出要测试测试项 
    def getCsvLimitContent(self,TestName,ParameterName):
        contentDict = {}

        for perLineDic in self.contentArray:

                if perLineDic["TestName"] == TestName and perLineDic["ParameterName"] == ParameterName:
                    # print("===========")
                    print(perLineDic)
                    
                    contentDict = perLineDic

        return contentDict


if __name__ == "__main__":
    getTech = LimitCsvProcess(os.path.join(Path(__file__).parent.parent,"Assets/Limits.csv"))
    print(getTech.getCsvLimitContent("Reset",'Delay500ms01'))

